import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/24 11:12
 */
public class T5 {
    public static void main(String[] args) {
        Scanner scannerString=new Scanner(System.in);
        Scanner scannerInt=new Scanner(System.in);
        Connection conn=null;
        PreparedStatement psmt=null;
        ResultSet rs=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/zhm";
            String user="root";
            String password="123456";
            conn= DriverManager.getConnection(url,user,password);
            String sql="SELECT id,name,age\n" +
                    "FROM user\n" +
                    "WHERE NAME=? and age=?";
            psmt=conn.prepareStatement(sql);
            System.out.println("用户名");
            String  name=scannerString.nextLine();
            System.out.println("年龄");
            int age=scannerInt.nextInt();
            psmt.setString(1,name);
            psmt.setInt(2,age);
            rs=psmt.executeQuery();
            System.out.println(name+"  "+age);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
